// pages/personcenter/personcenter.js
import {ApiRootUrl,apiList} from '../../../config/index.js'
import {
  request
} from "../../../utils/util.js"
import Toast from '../../../@vant/weapp/toast/toast';
import {IMG_PATH} from '../../../config/index.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    IMG_PATH:IMG_PATH,
    statusBarHeight: '',
    activeNames: "",
    dormManagerList:[],
    baseinfo:{
     
    },
    companyinfo:[
    ],
    susheinfo:{
     
    },
    tabList:[{
      title:'基本信息',
    },{
      title:'工作信息',
    },{
      title:'居住信息',
    }],
    employeeHr:{},
    active:0,
    optionId:''
  },
  backClick(){
    wx.navigateBack();
  },
  getBasciInfo(id,type){
    Toast.loading({
      message: '加载中...',
      mask: true,
      duration: 0,
      forbidClick: true,
    });
    request(apiList.personalDetail+"/"+id+"/"+type,{},"GET").then(res =>{
      
      var tabList
      if(res.data.dormWithManager == null){
        tabList=[{
          title:'基本信息',
        },{
          title:'工作信息',
        }]
      }else{
        tabList=[{
          title:'基本信息',
        },{
          title:'工作信息',
        },{
          title:'居住信息',
        }]
      }
      this.setData({
        baseinfo:res.data.employeeDetails,
        susheinfo:res.data.dormWithManager,
        companyinfo:res.data.inWorkWithHr,
        tabList:tabList,
        employeeInfo:res.data.employeeInfo,
        dormManagerList:res.data.dormWithManager == null ?[]: res.data.dormWithManager.dormManagerList,
        inWorkWithHr:res.data.inWorkWithHr == null ? []:res.data.inWorkWithHr.hrList== null ? [] :res.data.inWorkWithHr.hrList
      })
      Toast.clear();
    }).catch(err =>{
      Toast.clear();
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  onChange(event){
    this.setData({
      active:event.detail.index
    },()=>{
      
    })
  },
  onChange1(event){
    this.setData({
      activeNames: event.detail
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    let type = Number(options.type);  // 0 未入职 1 在职 2 离职
    this.setData({
      type:type
    })
    if(options.id){
      this.setData({
        optionId:options.id
      },()=>{
        this.getBasciInfo(options.id,type)
      })
    }
    
    this.setData({
      statusBarHeight:wx.getSystemInfoSync()['statusBarHeight']
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})